package com.concurrent;

import java.util.concurrent.ThreadFactory;

public class DefaultThreadFactory implements ThreadFactory {
    private ThreadGroup group ;
    private String threadName;

    public DefaultThreadFactory() {
        SecurityManager s = System.getSecurityManager();
        group = (s!=null) ? s.getThreadGroup():Thread.currentThread().getThreadGroup();
        threadName = "threadName";
    }

    @Override
    public Thread newThread(Runnable r) {
        Thread t = new Thread(group,r,threadName);
        if(t.isDaemon()){
            t.setDaemon(false); // 守护进程
        }
        return t;
    }
}
